﻿
@{
    ViewBag.Title = "任务详情";
    Layout = "~/Views/Shared/_detailBase.cshtml";
    if (false)
    {
        <script src="~/LiberUI/Scripts/jquery.js"></script>
        <script src="~/LiberUI/Scripts/jquery.ba-resize.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Base.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Controllers.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Action.js"></script>
        <script src="~/SiteUI/BaseScripts/site.js"></script>
    }
}
@section SideBar{
    <div id="TaskJournal">

    </div>
}
<div id="Detail">

</div>
<div id="tmp">
    @RenderPage("/SiteUI/wgBase.cshtml")
    @RenderPage("/SiteUI/Task/wgTask.cshtml")
</div>

<script>
    function getJournalEnd(rtn, state) {
        if (rtn.IsPositive) {
            var lst = $("#TaskJournal").html('');
            wgTask.CTask.Journal = rtn.Data.Logs;
            var cdate = null;
            var sdate = null;
            for (var i = 0; i < wgTask.CTask.Journal.length; i++) {
                var j = wgTask.CTask.Journal[i];
                var $item = $("<div>").addClass("JournalItem");
                var $head = $("<div>").addClass("JournalHead");
                //TODO:判断不同的动态类型（评论、新增、完成、打回、编辑）设置不同的图标
                var $icon = $("<div>").addClass("ItemIcon");

                //判断是否日期跳跃
                if (sdate == null) {
                    sdate = new Date(j.LogTime);
                }
                var day = new Date(j.LogTime);
                var interval = day.Betten(sdate);
                if (cdate == null || day.Betten(cdate).Days > 0) {
                    cdate = day;
                    $head.append($("<h4>").text(day.toLocaleString().split(' ')[0]));
                }
                else {
                    $head.append($("<h4>").text(' -'));
                }
                
                $head.append($("<h5>").addClass('timespan').text(day.toLocaleString().split(' ')[1]));
                var $cnt = $("<div>").addClass("JournalContent");

                if (interval.Days > 0) {
                    $cnt.append($("<h5>").text(interval.Days + '天'));
                }
                else if (interval.Hours > 0) {
                    $cnt.append($("<h5>").text(interval.Hours + '个小时'));
                }
                else if(interval.Months>0){
                    $cnt.append($("<h5>").text(interval.Months + '个月'));
                }
                else {

                }

                $cnt.append($("<h5>").text(j.Detail));
                $item.append($head)
                     .append($icon)
                     .append($cnt)
                     .append($("<div>").addClass('floatClear'));
                if (i == 0) {
                    $item.append($("<div>").addClass('TimeStar'));
                }
                lst.append($item);
                $item.fadeIn();
            }
        }
    };

    function newCommentOk() {
        new AjaxHelper('get', '/Task/GetJournal', { id: wgTask.CTask.IDStr }, getJournalEnd);
    };

    $(function () {
        Env.Task = '@ViewBag.Task'.ToJSON().Data;
        wgTask.vTaskView.appendTo($("#Detail"));
        wgTask.LoadTask(Env.Task);
        wgTask.vf_onNewCommentOk = newCommentOk;

        $("#TaskJournal").append(Env.aniLoading.clone().show());
        new AjaxHelper('get', '/Task/GetJournal', {id: wgTask.CTask.IDStr }, getJournalEnd);
    });
</script>

